package com.example.demo2.controller;

import com.example.demo2.bean.MessagesBean;
import com.example.demo2.service.MessagesBeanService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@CrossOrigin(origins = "*",
        methods = {RequestMethod.GET, RequestMethod.OPTIONS, RequestMethod.POST})
public class MessagesBeanController {
    @Autowired
    MessagesBeanService messagesBeanService;

    // 登录
//    @RequestMapping("/MessagesServer/Messagesbean/login")
//    public Map<String, Object> getMember(@RequestBody MessagesBean messagesBean) {
//        Map<String, Object> map = new HashMap<>();
//        MessagesBean messagesBean1 = messagesBeanService.login(messagesBean);
//        if (messagesBean1 != null) {
//            map.put("success", true);
//            map.put("msg", "成功");
//        } else {
//            map.put("success", false);
//            map.put("msg", "失败");
//        }
//        return map;
//    }

    // 注册
//    @RequestMapping("/MessagesServer/Messagesbean/register")
//    public Map<String, Object> addMember(@RequestBody MessagesBean messagesBean) {
//        Map<String, Object> map = new HashMap<>();
//        MessagesBean messagesBean1 = messagesBeanService.register(messagesBean);
//        if (messagesBean1 != null) {
//            map.put("success", true);
//            map.put("msg", "成功");
//        } else {
//            map.put("success", false);
//            map.put("msg", "失败");
//        }
//        return map;
//    }

    // 查询一个
    @RequestMapping("/app9/messages/findone")
    public Map<String, Object> findone(@RequestBody MessagesBean messagesBean) {
        Map<String, Object> map = new HashMap<>();
        MessagesBean messagesBean1 = messagesBeanService.findone(messagesBean);
        if (messagesBean1 != null) {
            map.put("success", true);
            map.put("msg", "成功");
            map.put("data", messagesBean1);
        } else {
            map.put("success", false);
            map.put("msg", "失败");
        }
        return map;
    }

    // 查询所有
    @RequestMapping("/app7/messages/list")
    public Map<String, Object> list() {
        Map<String, Object> map = new HashMap<>();
        List<MessagesBean> list = messagesBeanService.list();
        if (list != null) {
            map.put("success", true);
            map.put("msg", "成功");
            map.put("list", list);
        } else {
            map.put("success", false);
            map.put("msg", "失败");
        }
        return map;
    }

    // 删除
//    @RequestMapping("/MessagesServer/Messagesbean/delete")
//    public Map<String, Object> delete(@RequestBody MessagesBean messagesBean) {
//        Map<String, Object> map = new HashMap<>();
//        try {
//            messagesBeanService.deleteById(messagesBean.getId());
//            map.put("success", true);
//            map.put("msg", "成功");
//        } catch (Exception e) {
//            map.put("success", false);
//            map.put("msg", "失败");
//        }
//
//        return map;
//    }
    // 修改
//    @RequestMapping("/MessagesServer/Messagesbean/update")
//    public Map<String, Object> update(@RequestBody MessagesBean messagesBean) {
//        Map<String, Object> map = new HashMap<>();
//        MessagesBean messagesBean1 = messagesBeanService.update(messagesBean);
//        if (messagesBean1 != null) {
//            map.put("success", true);
//            map.put("msg", "成功");
//            map.put("data", messagesBean1);
//        } else {
//            map.put("success", false);
//            map.put("msg", "失败");
//        }
//        return map;
//    }
    // 添加
    @RequestMapping("/app8/messages/add")
    public Map<String, Object> addone(@RequestBody MessagesBean messagesBean) {
        Map<String, Object> map = new HashMap<>();
        MessagesBean messagesBean1 = messagesBeanService.addone(messagesBean);
        if (messagesBean1 != null) {
            map.put("success", true);
            map.put("msg", "成功");
            map.put("data", messagesBean1);
        } else {
            map.put("success", false);
            map.put("msg", "失败");
        }
        return map;
    }
}

